package com.emm.yixun.website.controller.router;
import java.util.ArrayList;
import java.util.List;

import com.emm.yixun.anotations.MerchantResourcesConfig;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.emm.yixun.common.model.Customer;
import com.emm.yixun.common.model.dto.EnumClass;
import com.emm.yixun.common.model.enums.PageInitEnum;
import com.emm.yixun.common.response.Response;
import com.emm.yixun.website.common.ajax.AjaxRes;
import com.emm.yixun.website.constant.ConstantConfig;
import com.emm.yixun.website.controller.base.BaseController;
import com.emm.yixun.website.utils.EnumUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/*
 * 映射规范：/router/一级模块简称/二级模块简称/页面简称
 * */
@Controller
@RequestMapping("/router/customer/")

public class CustomerRouterController extends BaseController<Customer>{
	@Autowired
	private ConstantConfig constantConfig;
	//跳转客户列表 

	@RequestMapping("customer/list")
	public String customerIndex() {
		return "/optimization/customer/customer/list";
	}
	
	//跳转分配列表 
	@RequestMapping("distribution/list")
    public String distributionIndex(){
    	return "/optimization/customer/distribution/list";
    }

	@RequestMapping(value = "getEnumJson")
	public @ResponseBody
	AjaxRes getEnumJson(String code) {
		AjaxRes res = getAjaxRes();
		List<EnumClass> json = EnumUtils.getEnumJson(PageInitEnum.getByNo(code).getDes());
		res.setObj(json);
		return res;
	}

	/**
	 * 客户跟进列表 功能描述: <br>
	 * 〈功能详细描述〉
	 * 
	 * @return
	 * @see [相关类/方法](可选)
	 * @since [产品/模块版本](可选)
	 */
	@RequestMapping("follow/list")
	public String followIndex() {
		return "/optimization/customer/follow/list";
	}

	/**
	 * 通话记录列表 功能描述: <br>
	 * 〈功能详细描述〉
	 * 
	 * @return
	 * @see [相关类/方法](可选)
	 * @since [产品/模块版本](可选)
	 */
	@RequestMapping("telRecord/list")
	public String telRecordIndex() {
		return "/optimization/customer/telRecord/list";
	}

	// 跳转新增客户
	@RequestMapping("customer/add")
	public String customerAdd() {
		return "/optimization/customer/customer/add";

	}
	@RequestMapping(value = "customer/downExcel")
	public @ResponseBody Response<String> downExcel(){
		Response<String> response = new Response<String>(true);
		response.setEntity(constantConfig.getCustomerTemplet());
		return response;
	}
	@RequestMapping(value = "customer/getTime")
	public @ResponseBody List<String> getTime(){
		int hBegin = 00,mBegin = 00,Hend = 23,mEnd= 45,step = 15;
		List<String> list = new ArrayList<String>();
		while (true) {
			if(mBegin==0){
				list.add(String.valueOf(hBegin)+":00");
			}else{
				list.add(String.valueOf(hBegin)+":"+String.valueOf(mBegin));
			}
			
			mBegin += step;
			if(mBegin>=60){
				mBegin = mBegin-60;
				hBegin++;
			}
			if(hBegin>Hend||(hBegin==Hend&&mBegin>mEnd)){
				break;
			}
		}
		return list;
	}

	// 跳转新增客户
	@RequestMapping("test")
	@MerchantResourcesConfig(resourcesCode="1111")
	public String test(HttpServletRequest request,HttpServletResponse response) {
		return "/optimization/customer/customer/add";

	}
}
